import request from '../utils/request.ts';

export async function getTipByCode(code: string): Promise<{ content: string }> {
	return request({
		url: '/quota/tipsetting/' + code,
		method: 'get'
	}).then(res => res.data);
}

export function getQrCodeById(id: string | number) {
	return request({
		url: '/quota/code/' + id,
		method: 'get'
	});
}


export interface QuotaInfo {
	companyName: string;
	legalPerson?: string;
	companyNo?: string;
	bankNo?: string;
	bankName?: string;
	bankPhone?: string;
	quotaAmount?: string;
	qrCodeId: string | number;
}

export type TableKey = keyof QuotaInfo;

export interface Field {
	id: number;
	name: string;
	tableKey: TableKey;
	showStatus: 1 | 0;
}

export function getFields(): Promise<{ rows: Field[] }> {
	return request({
		url: '/quota/field/list',
		method: 'get'
	});
}

export function save(data: QuotaInfo): Promise<{ id: number }> {
	return request({
		url: '/quota/info',
		method: 'post',
		data
	});
}

export function getResult(id: number | string): Promise<{ data: { quotaAmount: number } }> {
	return request({
		url: '/quota/setting/' + id,
		method: 'get'
	});
}

export function confirm(data: any): Promise<{ id: number }> {
	return request({
		url: '/quota/setting',
		method: 'put',
		data
	});
}

export function uploadFile(data: any) {
	return request({
		url: '/common/upload',
		method: 'post',
		data,
		headers: {
			"Content-Type": "multipart/form-data", // 必须显式声明
		},
	})
}